package com.begonzales.locker.dto;

import com.begonzales.locker.mapper.CTable;
import com.begonzales.locker.mapper.CTableColumns;
import com.begonzales.locker.util.HelperFunc;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import sun.reflect.generics.tree.ReturnType;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: BGONZ8
 * Date: 9/20/11
 * Time: 12:01 PM
 * To change this template use File | Settings | File Templates.
 */
public class MapperDomainTestCase {
    private String name;
    private String domainName;
    private CTable table;

    private List<ItemDTO> items;

	public void toFile(String fileName)
	{
		try {
            File removeFile = new File(fileName);
            if ( removeFile.exists())
            {
                removeFile.delete();
            }
		    BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
		    out.write( toString() );
		    out.close();
		} catch (IOException e) {
		}
	}

    public String toString()
    {
        String retval = "";
        retval = retval + "" +
                "package com.nike.brand.thelocker.mapper."+HelperFunc.firstLetterCap(this.getDomainName())+";  \r\n" +
                "\n" +
                "import com.nike.brand.thelocker.domain."+HelperFunc.firstLetterCap(this.getDomainName())+";\n" +
                "import com.nike.brand.thelocker.mapper.AbstractDbMapperTestCase;\n" +
                "import com.nike.brand.thelocker.mapper.GenericCRUDMapper;\n" +
                "import org.junit.Test;\n" +
                "import org.springframework.beans.factory.annotation.Autowired;\n" +
                "\n" +
                "import java.math.BigDecimal;\n" +
                "import java.util.Arrays;\n" +
                "import java.util.HashMap;\n" +
                "import java.util.List;\n" +
                "import java.util.Map;\n" +
                "import java.util.concurrent.atomic.AtomicInteger;\n" +
                "\n" +
                "import static org.junit.Assert.assertEquals;\n" +
                "import static org.junit.Assert.assertNotNull;" +
                "\n" +
                "/**\n" +
                " *\n" +
                " */\n" +
                "public class "+this.getDomainName()+"MapperTestCase extends AbstractDbMapperTestCase<"+this.getDomainName()+">\n" +
                "{\n" +
                "\tprivate static final AtomicInteger COUNTER = new AtomicInteger(1); \n" +
                "\n" +
                "\n" +
                "    @Autowired\n" +
                "    private "+this.getDomainName()+"Mapper "+ HelperFunc.firstLetterLowerCap(this.getDomainName())+"Mapper;" +
                "\n" +
                "\n" +
                "    @Override\n" +
                "    protected GenericCRUDMapper<"+this.getDomainName()+"> getCRUDMapper() {\n" +
                "        return "+ HelperFunc.firstLetterLowerCap(this.getDomainName())+"Mapper;\n" +
                "    }" +
                "\n" +
                "\n" +
                "    @Override\n" +
                "    protected List<"+HelperFunc.firstLetterCap(this.getDomainName())+"> createEntitiesForInsert() {\n" +
                "        "+HelperFunc.firstLetterCap(this.getDomainName())+" "+HelperFunc.firstLetterLowerCap(this.getDomainName())+" = createEntityForInsert();\n" +
                "        return Arrays.asList("+HelperFunc.firstLetterLowerCap(this.getDomainName())+");\n" +
                "    }" +
                "" +
                "\n" +
                "\n" +
                "    public static "+HelperFunc.firstLetterCap(this.getDomainName())+" createEntityForInsert() {\n" +
                "        int instanceNumber = COUNTER.getAndIncrement();\n" +
                "        "+HelperFunc.firstLetterCap(this.getDomainName())+" item = new "+HelperFunc.firstLetterCap(this.getDomainName())+"();\n" +
                "        item.setId(null);\n" +
                "        return item;\n" +
                "    }\n" +
                "\n" +
                "\n" +
                "    @Override\n" +
                "    protected "+this.getDomainName()+" updateEntity("+this.getDomainName()+" entityToUpdate) {\n" +
                "        entityToUpdate.setAllotmentDescription( entityToUpdate.getAllotmentDescription() + \".updated\" );\n" +
                "        return entityToUpdate;\n" +
                "    }" +
                "\n\n" +
                "}\n";
        return  retval;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<ItemDTO> getItems() {
        return items;
    }

    public void setItems(List<ItemDTO> items) {
        this.items = items;
    }

    public String getDomainName() {
        return domainName;
    }

    public void setDomainName(String domainName) {
        this.domainName = domainName;
    }

    public CTable getTable() {
        return table;
    }

    public void setTable(CTable table) {
        this.table = table;
    }


}
